<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<script type="text/javascript" src="priority_queue.js"></script>
<script type="text/javascript">
const BETTER = 1;
const WORSE = -1;
function isBetter(a, b){
	if(a.mark > b.mark){
		return BETTER;
	} else {
		return WORSE;
	}
}

function Student(name, mark){
	this.name = name;
	this.mark = mark;
	return this;
}
var hoang = new Student("hoang", 9);
var oanh = new Student("oanh", 8.5);
var chuyen = new Student("chuyen", 7.5);
var gam = new Student("gam", 10);

var pq = new PriorityQueue({cmpFunc : isBetter});
pq.push(oanh);
pq.push(chuyen);
pq.push(hoang);

document.write("Size of pq = "  + pq.getSize()+"<br/>");
document.write("Check hoang is in pq? Answer: " + pq.isIncluded(hoang)+"<br/>");
document.write("Check gam is in pq? Answer: " + pq.isIncluded(gam)+"<br/>");


function displayStudent(x){
	document.write("Student " + x.name + " " + x.mark + "<br/>");
}
pq.displayOne = displayStudent;

pq.display();
document.write("<p/>");
oanh.mark++;
chuyen.mark+=2.5;
pq.adjust();
pq.display();

document.write("<p/>");
document.write("Index of hoang? Answer: " + pq.indexOf(hoang) + "<br/>");
document.write("Index of gam? Answer: " + pq.indexOf(gam) + "<br/>");

/*
document.write("<p/>");
pq.remove(hoang);
pq.display();
*/

document.write("<p/>");
pq.removeAt(pq.indexOf(hoang));
pq.display();

document.write("Test top key: " + pq.top().mark + "<br/>");

/*
var i = 0;
while(!pq.isEmpty()){
	var x = pq.pop();
	document.write(++i + " " + x.name + " " + x.mark + "<br/>");	
}
*/

</script>

</body>
</html>